import { Controller, Get, Param, ParseIntPipe,BadRequestException, Query, Req, SetMetadata } from '@nestjs/common';
import { AppService } from './app.service';
import { JwtService } from '@/common/jwt/jwt.service'
import { Log } from '@/common/logger/logger.decorator'; //日志装饰器
import { Util } from './common/util/util.service';


@Controller()
@SetMetadata('isNoAuth', true)//token认证忽略

@SetMetadata('isLogger',true)
export class AppController {
  constructor(private readonly appService: AppService, private readonly jwtService: JwtService,
    private readonly util: Util
  ) { }

  @Get()
  getHello(@Req() req): string {
    const { userInfo } = req;
    console.log(userInfo);
    return this.appService.getHello();
  }

  @Log()//日志
  @Get('/test')
  async createToekn() {
    // await this.util.sleep(5000)
    const token = await this.jwtService.generateToken('100086');
    return token;
  }
  @Get('/findByWhereJson')
  getOne() {
    return this.appService.findByWhereJson()
  }

  @Get('/getList')
  getList() {
    // return this.appService.getList()
  }

  @Get('/add')
  add() {
    return this.appService.add()
  }


  @Get('/del')
  del() {
    return this.appService.del()
  }

  @Get('/select')
  type() {
    return this.appService.select()
  }

  @Get('/count')
  count(){
    return this.appService.count()
  }

  @Get('/update')
  update() {
    return this.appService.update()
  }

  @Get('/updatebyid')
  updateById(@Query('id') id: string) {
    console.log('id',id)
    return this.appService.updateById(id)
  }

  @Get('/updateAndReturn')
  updateAndReturn() {
    return this.appService.updateAndReturn()
  }

  @Get('/setById')
  setById() {
    return this.appService.setById()
  }

  @Log()//日志
  @Get("/adds")
  adds() {
    return this.appService.adds()
  }

  @Get("/delById")
  delById() {
    return this.appService.delById()
  }

}
